#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>

class Solution {
public:
    vector<string> ret;
    string path;
    vector<string> letterCombinations(string digits) {
        if (digits.size() == 0)
            return ret;
        vector<string> tmp = { "","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };
        dfs(digits, tmp, 0);
        return ret;
    }
    void dfs(string& digits, vector<string>& tmp, int pos)
    {
        if (pos == digits.size())
        {
            ret.push_back(path);
            return;
        }

        int index = digits[pos] - '0';
        for (int j = 0; j < tmp[index].size(); j++)
        {
            path.push_back(tmp[index][j]);
            dfs(digits, tmp, pos + 1);
            path.pop_back();
        }


    }
};

class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;
    vector<bool> check;
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        if (nums.size() == 0)
            return ret;
        sort(nums.begin(), nums.end());
        check.resize(nums.size(), true);
        dfs(nums, 0);
        return ret;

    }
    void dfs(vector<int>& nums, int pos)
    {

        if (pos == nums.size())
        {
            ret.push_back(path);
            return;
        }
        for (int i = 0; i < nums.size(); i++)
        {
            if (check[i] && (i == 0 || nums[i] != nums[i - 1] || check[i - 1] == false))
            {
                path.push_back(nums[i]);
                check[i] = false;
                dfs(nums, pos + 1);
                path.pop_back();
                check[i] = true;
            }
        }
    }
};
vector<vector<int>> permuteUnique(vector<int>& nums) {
    check.resize(nums.size(), true);
    dfs(nums, 0);
    return ret;

}
int main()
{
    vector<int> nums = { 1,2,3 };
    permuteUnique(nums);
    return 0;
}